//
//  main.m
//  NSMutable
//
//  Created by admin on 2019/8/8.
//  Copyright © 2019 猫爷爷的酱醋茶. All rights reserved.
//

/*
 
 NSMutableDictionary
    是NSFDictionary的子类
 
    同样，初始化不能取父类独有的对象，例
     NSMutableDictionary *dict = @{
        //...
     }
 
    正确的初始化：
    + (instancetype)dictionaryWithObjectsAndKeys:(id)firstObject, ...
 
    字典的增加
    - (void)setObject:(ObjectType)anObject forKey:(KeyType <NSCopying>)aKey;
    如果有相同的key，则是修改
 
    字典的删除
    - (void)removeObjectForKey:(KeyType)aKey;
 
    //字典的持久化
    读写到磁盘里。
 
 */

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    //按值键的顺序填写字典
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"猫爷爷的酱醋茶",@"name",@"IOS开发者",@"Career", nil];
    
    for(id key in dict)
    {
        NSLog(@"%@ = %@",key,dict[key]);
    }
    
    NSLog(@"-----------------");
    
    //增加
    [dict setObject:@"IOS初级工程师" forKey:@"grade"];
    for(id key in dict)
    {
        NSLog(@"%@ = %@",key,dict[key]);
        
    }
    
    NSLog(@"~~~~~~~~~~~~~~~~~");
    
    //有相同的key，则为修改
    [dict setObject:@"IOS中级工程师" forKey:@"grade"];
    for(id key in dict)
    {
        NSLog(@"%@ = %@",key,dict[key]);
        
    }
    
    NSLog(@"___________________");
    
    //删除
    //- (void)removeObjectForKey:(KeyType)aKey;
    [dict removeObjectForKey:@"grade"];
    for(id key in dict)
    {
        NSLog(@"%@ = %@",key,dict[key]);
        
    }
    
    //写入磁盘
    [dict writeToFile:@"/Users/Admin/Desktop/abc.plist" atomically:NO];
    
    //读取
    NSMutableDictionary *dictOne = [NSMutableDictionary dictionaryWithContentsOfFile:@"/Users/Admin/Desktop/abc.plist"];
    
    NSLog(@"%@",dictOne);
    
    return 0;
}
